SHELL=bash


# Very fast, low memory URL parser in C
#   http://github.com/nathanwiegand/urlparser
# currently using revision 10
URL_VERSION=11
ext/urlparser-$(URL_VERSION)/urlparser.o:
	mkdir -p ext; \
	pushd ext; \
	svn co -r$(URL_VERSION) http://svn.github.com/nathanwiegand/urlparser.git urlparser-$(URL_VERSION); \
	rm -f urlpaser; \
	ln -s urlparser-$(URL_VERSION) urlparser; \
	pushd urlparser; \
	$(CC) $(CFLAGS) -c urlparser.c; 
REALCLEAN_OBJS+=ext/urlparser-$(URL_VERSION) ext/urlparser
EXT+=ext/urlparser-$(URL_VERSION)/urlparser.o


# v8: Google's JavaScript interpreter.
#   http://code.google.com/p/v8/
# currently using revision 4439
ifeq ($(shell gcc -v 2>&1| tail -n 1 | grep " 4.4"|wc -l), 1)
  VERSIONFIX=export GCC_VERSION=44
else
  VERSIONFIX=echo ""
endif

V8_VERSION=4439
ext/v8-$(V8_VERSION)/libv8.a:
	mkdir -p ext; \
	pushd ext; \
	svn checkout -r$(V8_VERSION) http://v8.googlecode.com/svn/trunk/ v8-$(V8_VERSION); \
	rm -f v8; \
	ln -s v8-$(V8_VERSION) v8; \
	pushd v8; $(VERSIONFIX) && scons mode=release snapshot=on library=static; popd

ext/v8/libv8.a: ext/v8-$(V8_VERSION)/libv8.a

EXT+=ext/v8/libv8.a
REALCLEAN_OBJS+=ext/v8 ext/v8-$(V8_VERSION)

# libcurl
LIBCURL_VERSION=7.20.1
ext/libcurl: 
	mkdir -p ext; \
	pushd ext; \
	wget http://curl.online-mirror.de/download/curl-$(LIBCURL_VERSION).tar.gz;\
	tar xvzf curl-$(LIBCURL_VERSION).tar.gz; \
	rm -f libcurl; \
	ln -s curl-$(LIBCURL_VERSION) libcurl; \
	pushd libcurl; \
	export CFLAGS=-m32; \
	./configure --without-libidn;\
	make
  
EXT+=ext/libcurl
REALCLEAN_OBJS+=ext/libcurl ext/curl-$(LIBCURL_VERSION) ext/curl-$(LIBCURL_VERSION).tar.gz

# GoogleTest framework
#   http://code.google.com/p/googletest/ 
#
GOOGLETEST_VERSION=1.5.0
ext/gtest-$(GOOGLETEST_VERSION)/lib/libgtest.la:
	mkdir -p ext; \
	pushd ext;		\
	wget http://googletest.googlecode.com/files/gtest-1.5.0.tar.gz; \
	rm -f googletest; \
  tar xvzf gtest-$(GOOGLETEST_VERSION).tar.gz; \
	ln -s gtest-$(GOOGLETEST_VERSION) googletest;	\
	pushd googletest; \
	./configure  CXXFLAGS='-m32' CFLAGS='-m32' && make;
EXT+=ext/gtest-$(GOOGLETEST_VERSION)/lib/libgtest.la
REALCLEAN_OBJS+=ext/googletest ext/gtest-$(LIBCURL_VERSION) ext/gtest-$(LIBCURL_VERSION).tar.gz
	

# JDK 1.6 32bit version
# TODO(nathan,crutcher): Figure out a better way to fetch this requirement since
# we're having to re-host on Google Docs.  
JDKPATH=jdk1.6.0_20
ext/$(JDKPATH)/jre/lib/i386/libjava.so:
	mkdir -p ext; \
	pushd ext;\
  wget --save-cookies cookie --user-agent "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)" \
    -O java.bin \
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=0B0QJnkXqZIQqNGQ2OGQ1YzktYzQ2OC00NDhlLWEwN2QtOTRmMTdmYjFmOGJh" \
--referer "https://docs.google.com/uc?export=download&confirm=no_antivirus&id=0B0QJnkXqZIQqNGQ2OGQ1YzktYzQ2OC00NDhlLWEwN2QtOTRmMTdmYjFmOGJh"; \
  wget --load-cookies cookie --user-agent "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)" \
    -O java.bin \
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=0B0QJnkXqZIQqNGQ2OGQ1YzktYzQ2OC00NDhlLWEwN2QtOTRmMTdmYjFmOGJh" \
--referer "https://docs.google.com/uc?export=download&confirm=no_antivirus&id=0B0QJnkXqZIQqNGQ2OGQ1YzktYzQ2OC00NDhlLWEwN2QtOTRmMTdmYjFmOGJh"; \
	chmod +x java.bin;\
	./java.bin	
EXT+=ext/$(JDKPATH)/jre/lib/i386/libjava.so
REALCLEAN_OBJS+=ext/$(JDKPATH)
